extern int main();
extern void SystemInit();
extern void __libc_init_array();
/*
naked 属性 告诉编译器 不生成 压栈汇编 push {r7, lr}等指令

ARM 状态与 Thumb 状态
有些处理器同时支持 ARM 和 Thumb 指令集，通过 BX 或 BLX 指令进行切换，当指令 BX 跳转地址的 LSB 位为 1，表示切换到 Thumb 状态，为 0 则切换到 ARM 状态。

无论是 ARM 还是 Thumb，其指令在存储器中都是边界对齐的（2字节或4字节对齐），也就是地址的最低位总是 0。 因此，在执行跳转过程中，PC 寄存器中的最低位被舍弃，不起作用。 在 BX 指令的执行过程中，最低位正好被用作状态判断的标志，不会造成存储器访问不对齐的错误。

Cortex-M 系列处理器不支持 ARM 指令，因此也不存在 ARM 状态，所以反汇编中的函数地址最低位都是 1

bin 部分数据含义
0x8000000-0x8000003  ：中断向量表定义 栈顶指针，SRAM最大地址  送  SP
0x8000004-0x8000008  : 存储 reset中断函数地址（_start_func） 送  PC
 */

// reset handle

__attribute__((naked)) void _start_func()
{
    extern unsigned int _sidata, _sdata, _edata, _sbss, _ebss;

	unsigned int *sdata = &_sdata;		   // 0x20000000
	unsigned int *data_atflash = &_sidata; // 0x80000xx

	// copy data from flash to sram
	sdata = &_sdata;         // 0x20000000
	data_atflash = &_sidata; // 0x80000xx
	while (sdata < &_edata)
	{
		*sdata++ = *data_atflash++;
	}

	/*clear bss*/
	sdata = &_sbss;
	while (sdata < &_ebss)
	{
		*sdata++ = 0;
	}

	__libc_init_array();
	//SystemInit();
	 main();
}

/***********************中断向量声明******************************* */
//  声明 中断函数 防止编译器报错
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif

__WEAK void NMI_Handler()
{
	for (;;)
	{
	}
}

__WEAK void HardFault_Handler()
{
	for (;;)
	{
	}
}

__WEAK void MemManage_Handler()
{
	for (;;)
	{
	}
}

__WEAK void BusFault_Handler()
{
	for (;;)
	{
	}
}

__WEAK void UsageFault_Handler()
{
	for (;;)
	{
	}
}

__WEAK void SVC_Handler()
{
	for (;;)
	{
	}
}

__WEAK void DebugMon_Handler()
{
	for (;;)
	{
	}
}

__WEAK void PendSV_Handler()
{
	for (;;)
	{
	}
}

__WEAK void SysTick_Handler()
{
	for (;;)
	{
	}
}

__WEAK void WWDG_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void PVD_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void TAMPER_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void RTC_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void FLASH_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void RCC_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void EXTI0_IRQHandler()
{
	for (;;)
	{
	}
}
__WEAK void EXTI1_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void EXTI2_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void EXTI3_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void EXTI4_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void DMA1_Channel1_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void DMA1_Channel2_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void DMA1_Channel3_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void DMA1_Channel4_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void DMA1_Channel5_IRQHandler()
{
	for (;;)
	{
	}
}
__WEAK void DMA1_Channel6_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void DMA1_Channel7_IRQHandler()
{
	for (;;)
	{
	}
}

__WEAK void ADC1_2_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak USB_HP_CAN1_TX_IRQHandler
//   .thumb_set USB_HP_CAN1_TX_IRQHandler,Default_Handler

__WEAK void USB_HP_CAN1_TX_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak USB_LP_CAN1_RX0_IRQHandler
//   .thumb_set USB_LP_CAN1_RX0_IRQHandler,Default_Handler
__WEAK void USB_LP_CAN1_RX0_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak CAN1_RX1_IRQHandler
//   .thumb_set CAN1_RX1_IRQHandler,Default_Handler
__WEAK void CAN1_RX1_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak CAN1_SCE_IRQHandler
//   .thumb_set CAN1_SCE_IRQHandler,Default_Handler
__WEAK void CAN1_SCE_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak EXTI9_5_IRQHandler
//   .thumb_set EXTI9_5_IRQHandler,Default_Handler
__WEAK void EXTI9_5_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM1_BRK_IRQHandler
//   .thumb_set TIM1_BRK_IRQHandler,Default_Handler
__WEAK void TIM1_BRK_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM1_UP_IRQHandler
//   .thumb_set TIM1_UP_IRQHandler,Default_Handler
__WEAK void TIM1_UP_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM1_TRG_COM_IRQHandler
//   .thumb_set TIM1_TRG_COM_IRQHandler,Default_Handler
__WEAK void TIM1_TRG_COM_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM1_CC_IRQHandler
//   .thumb_set TIM1_CC_IRQHandler,Default_Handler
__WEAK void TIM1_CC_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM2_IRQHandler
//   .thumb_set TIM2_IRQHandler,Default_Handler
__WEAK void TIM2_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM3_IRQHandler
//   .thumb_set TIM3_IRQHandler,Default_Handler
__WEAK void TIM3_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak TIM4_IRQHandler
//   .thumb_set TIM4_IRQHandler,Default_Handler
__WEAK void TIM4_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak I2C1_EV_IRQHandler
//   .thumb_set I2C1_EV_IRQHandler,Default_Handler
__WEAK void I2C1_EV_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak I2C1_ER_IRQHandler
//   .thumb_set I2C1_ER_IRQHandler,Default_Handler
__WEAK void I2C1_ER_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak I2C2_EV_IRQHandler
//   .thumb_set I2C2_EV_IRQHandler,Default_Handler
__WEAK void I2C2_EV_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak I2C2_ER_IRQHandler
//   .thumb_set I2C2_ER_IRQHandler,Default_Handler
__WEAK void I2C2_ER_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak SPI1_IRQHandler
//   .thumb_set SPI1_IRQHandler,Default_Handler
__WEAK void SPI1_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak SPI2_IRQHandler
//   .thumb_set SPI2_IRQHandler,Default_Handler
__WEAK void SPI2_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak USART1_IRQHandler
//   .thumb_set USART1_IRQHandler,Default_Handler
__WEAK void USART1_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak USART2_IRQHandler
//   .thumb_set USART2_IRQHandler,Default_Handler
__WEAK void USART2_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak USART3_IRQHandler
//   .thumb_set USART3_IRQHandler,Default_Handler
__WEAK void USART3_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak EXTI15_10_IRQHandler
//   .thumb_set EXTI15_10_IRQHandler,Default_Handler
__WEAK void EXTI15_10_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak RTC_Alarm_IRQHandler
//   .thumb_set RTC_Alarm_IRQHandler,Default_Handler
__WEAK void RTC_Alarm_IRQHandler()
{
	for (;;)
	{
	}
}

//   .weak USBWakeUp_IRQHandler
//   .thumb_set USBWakeUp_IRQHandler,Default_Handler
__WEAK void USBWakeUp_IRQHandler()
{
	for (;;)
	{
	}
}

/*中断向量表 占用data 区*/
extern unsigned int _end_stack_bottom;
__attribute__((section(".vector"))) const void *__Vectors[] = {
	(void *)(&_end_stack_bottom), /*ram最大地址*/
	/*reset_handler 单片机复位后从这个地址开始运行 */
	/*cortex M只支持thumb2 指令，机器码最低位强制是1，所以地址会+1 */
	_start_func,
	NMI_Handler,
	HardFault_Handler,
	MemManage_Handler,
	BusFault_Handler,
	UsageFault_Handler,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	SVC_Handler,
	DebugMon_Handler,
	(void *)0l,
	PendSV_Handler,
	SysTick_Handler,

	/*外设中断*/

	WWDG_IRQHandler,
	PVD_IRQHandler,
	TAMPER_IRQHandler,
	RTC_IRQHandler,
	FLASH_IRQHandler,
	RCC_IRQHandler,
	EXTI0_IRQHandler,
	EXTI1_IRQHandler,
	EXTI2_IRQHandler,
	EXTI3_IRQHandler,
	EXTI4_IRQHandler,
	DMA1_Channel1_IRQHandler,
	DMA1_Channel2_IRQHandler,
	DMA1_Channel3_IRQHandler,
	DMA1_Channel4_IRQHandler,
	DMA1_Channel5_IRQHandler,
	DMA1_Channel6_IRQHandler,
	DMA1_Channel7_IRQHandler,
	ADC1_2_IRQHandler,
	USB_HP_CAN1_TX_IRQHandler,
	USB_LP_CAN1_RX0_IRQHandler,
	CAN1_RX1_IRQHandler,
	CAN1_SCE_IRQHandler,
	EXTI9_5_IRQHandler,
	TIM1_BRK_IRQHandler,
	TIM1_UP_IRQHandler,
	TIM1_TRG_COM_IRQHandler,
	TIM1_CC_IRQHandler,
	TIM2_IRQHandler,
	TIM3_IRQHandler,
	TIM4_IRQHandler,
	I2C1_EV_IRQHandler,
	I2C1_ER_IRQHandler,
	I2C2_EV_IRQHandler,
	I2C2_ER_IRQHandler,
	SPI1_IRQHandler,
	SPI2_IRQHandler,
	USART1_IRQHandler,
	USART2_IRQHandler,
	USART3_IRQHandler,
	EXTI15_10_IRQHandler,
	RTC_Alarm_IRQHandler,
	USBWakeUp_IRQHandler,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	(void *)0l,
	(void *)0xF108F85F /*BOOTRAM*/
};
